<?php
/**
 * Description of IndirizzoDataManager
 *
 * @author rocco
 */
class IndirizzoDataManager
{
    private static $instance;

    public static function getInstance()
    {
        if(self::$instance == null)
        {
            $c = __CLASS__;
            self::$instance = new $c;
        }
        return self::$instance;
    }
    public function getIndirizzi($connection)
    {
        $query = "Select * from Indirizzo ";
        $result = $connection->query($query);
        return $result;
    }

    public function getCodiceIndirizzo($connection, $descrizione)
    {
        $query = "Select codice from Indirizzo where descrizione = ? ";
        if($stmt = $connection->prepare($query))
        {
            $stmt->bind_param( "s", $descrizione);
            $stmt->execute();
        }

        $stmt->bind_result($codice);

        $result = -1;

        if ($stmt->fetch())
        {
            $result = $codice;
        }
        $stmt->close();
        return $result;
        
    }

    public function insertIndirizzo($connection, $descrizione)
    {
        $query = "Insert into Indirizzo (descrizione) VALUES(?) ";
        $stmt = $connection->prepare($query);
        $stmt->bind_param( "s", $descrizione);
        $stmt->execute();
        $stmt->close();
    }
}
?>
